<layout name="page" />
<block name="content">
	{:widget('page_header/simple',array('name'=>$tag_name))}
	<div class="operate-panel">
		<a class="btn btn-return" onclick="go_return_url()">返回</a>
		<i class="mid"></i>
		<a onclick="add()" class="btn btn-normal">新增</a>
		<a id="btn_save" class="btn btn-normal">保存</a>
		<i class="split"></i>
		<a onclick="del()"class="btn btn-del">删除</a>
	</div>
	<div class="x1 sub box">
		<div class="w28 m100 frame" style="max-height:500px;overflow-y: auto;">
			<div class="tree-menu">
				{:widget('html/tree_menu',array($tree_menu))}
			</div>
		</div>
		<div style="width:16px;"></div>
		<div class="x1 frame m100" style="height:500px;">
			<form id="form_data" name="form_data" method="post" style="width:100%;">
				<input type="hidden" name="id" id="id">
				<input type="hidden" name="pid" id="pid" value="0">
				<input type="hidden" name="ajax" id="ajax" value="0">
				<input type="hidden" name="opmode" id="opmode" value="">
				<select name="tag_list" id="tag_list" class="hidden">
					{:fill_option($tag_list)}
				</select>
				<div class="col-12 box">
					<label class="input-label" for="name">名称*：</label>
					<input class="input w19" type="text" id="dept_no" name="name" check="required" info="请输入名称" class="input">
				</div>
				<if condition="$has_pid">
					<div class="col-12 box">
						<label class="input-label" for="pid_name">父节点*：</label>
						<div class="input-box w19">
							<input name="pid" id="pid" type="hidden" info="请选择父节点" check="required" />
							<input class="input" name="pid_name"  id="pid_name" type="text" readonly="readonly" info="请选择上级部门" check="required"/>
							<a class="add-on w6" onclick="select_pid();">选择</a>
						</div>
					</div>
				</if>
				<div class="col-12 box">
					<label class="input-label" for="sort">排序：</label>
					<input type="text" id="sort" name="sort" class="input w10">
				</div>
				<div class="col-12 box">
					<label class="input-label" for="is_del">状态：</label>
					<select   name="is_del" id="is_del" class="select w10">
						<option value="">请选择</option>
						<option  value="0">启用</option>
						<option value="1">禁用</option>
					</select>
					<i class="icon"></i>
				</div>
				<div class="col-12 box">
					<label class="input-label" for="remark">备注：</label>
					<textarea id="remark" name="remark" rows="5" class="textarea"></textarea>
				</div>
			</form>
		</div>
	</div>

</block>
<block name="js">
	<script type="text/javascript">
		layui.use(['global'], function() {
			var $ = layui.jquery;
			var fn = {
				add : function() {
					winopen("{:url('system_tag/add',array('controller'=>$controller))}", 560, 470);
				},
				save : function() {
					if ($("#opmode").val() == "") {
						layer.msg("请选择文件夹或新增");
					}
					send_form("form_data", "__SELF__", "__SELF__", function(ret) {
						if (ret.status) {
							layer.msg(ret.info);
							location.reload(true);
						} else {
							layer.msg(ret.info);
							return false;
						}
					});
				},
				del : function() {
					if ($(".sub-sidebar a.active").length == 0) {
						layer.msg('请选择要删除的数据');
						return false;
					}
					if ($(".sub-sidebar a.active").parent().find(".tree_menu").html() != undefined) {
						layer.msg('有子数据不能删除');
						return false;
					}
					//信息框-例2
					$("#opmode").val("del");
					layer.msg('确定要删除吗?', {
						time : 0,
						btn : ['确定', '取消'],
						yes : function(index) {
							var vars = $("#form_data").serialize();
							send_ajax("__SELF__", vars, function(ret) {
								if (ret.status) {
									layer.msg(ret.info, function() {
										location.reload(true);
									});
								} else {
									layer.msg(ret.info);
									return false;
								}
							});
						},
						no : function(index) {
							layer.close(index);
						}
					});
				},
				select_pid : function() {
					winopen("{:url('system_tag/select_pid?controller='.APP_NAME)}", 560, 470);
				}
			};
			win_exp(fn);

			$(".sub-sidebar .tree_menu  a").click(function() {
				$(".sub-sidebar .tree_menu  a").removeClass("active");
				$(this).addClass("active");
				send_ajax("{:url('system_tag/read')}", "id=" + $(this).attr("node"), function(data) {
					show_data(data);
				});
				return false;
			});

			function show_data(result) {
				for (var s in result.data) {
					set_val(s, result.data[s]);
				}
				if ($("#pid").val() == 0) {
					$("#tag_name").val("根节点");
				} else {
					$("#tag_name").val($("#tag_list option[value='" + $("#pid").val() + "']").text());
				}
				$("#opmode").val("edit");
			};
		});

	</script>
</block>